package com.thoughtworks.jspecsupport;

import com.intellij.openapi.vfs.VirtualFile;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class JSpecTestFilePicker {

    private List<String> libs = Arrays.asList("jquery-1.3.2.min.js",
            "jquery.js",
            "jspec.js",
            "env.rhino.js");

    public boolean isMatch(VirtualFile file) {
        try {
            String fileSource = new String(file.contentsToByteArray());
            return isMatch(fileSource, file.getName());
        } catch (IOException e) {
            return false;
        }
    }


    public boolean isMatch(String source, String fileName) {
        if (!libs.contains(fileName)) {
            return source.contains("JSpec.describe") && source.contains("should.be");
        }
        return false;
    }

}
